package com.example.ai.controller;

import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageModel;
import org.springframework.ai.openai.OpenAiImageOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OpenAIImageController {
    @Autowired
    OpenAiImageModel openaiImageModel;
    @GetMapping(value = "/ai/image/generate",produces = "text/html;charset=utf-8")
    public String generateImage(String prompt) {
        /**
        ImageResponse response = openaiImageModel.call(
                new ImagePrompt(prompt,
                        OpenAiImageOptions.builder()
                                .quality("hd")
                                .N(4)
                                .height(1024)
                                .width(1024).build())

        );
         */
        ImageResponse response = openaiImageModel.call(
                new ImagePrompt(prompt)
        );
        Image output = response.getResult().getOutput();
        String url = output.getUrl();
        String b64Json = output.getB64Json();
        //return url;
        return "<img src='"+url+"'/>";

    }
}
